import { getProjectQutaListApi } from '@/views/project/projectquota/api/projectquota.api';
import { getProjectMaintainListApi } from '@/views/project/projectmaintain/api/projectmaintain.api';
import { getProjectDevelopListApi } from '@/views/project/projectdevelop/api/projectdevelop.api';

const state = {
  projectQuotaList: [],
  projectMaintainList: [],
  projectDevelopList: []
};

const mutations = {
  SET_PROJECTQUOTA_LIST: (state, data) => {
    state.projectQuotaList = data;
  },
  SET_PROJECTMAINTAIN_LIST: (state, data) => {
    state.projectMaintainList = data;
  },
  SET_PROJECTDEVELOP_LIST: (state, data) => {
    state.projectDevelopList = data;
  }
};

const actions = {
  getProjectQuotaList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getProjectQutaListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_PROJECTQUOTA_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  },
  getProjectMaintainList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getProjectMaintainListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_PROJECTMAINTAIN_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  },
  getProjectDevelopList({ commit }, queryParams) {
    return new Promise((resolve, reject) => {
      getProjectDevelopListApi(queryParams).then(response => {
        const { data } = response;
        const { results } = data
        commit('SET_PROJECTDEVELOP_LIST', results);
        resolve(response)
      }).catch(error => {
        reject(error);
      });
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
